#pragma once
#include "sgptr.h"
#include "sgobject.h"
#include "sgcomposite.h"
#include <map>
#include <gl/gl.h>
#include "graphics/Texture.h"
#include "FerrisWheelFactory.h"
#include "YoYoFactory.h"
#include "ScramblerFactory.h"
#include "ObservationTowerFactory.h"
#include "GravitronFactory.h"

class CarnivalBuilder
{
public:
	CarnivalBuilder(void);
	~CarnivalBuilder(void);

	void CarnivalGrounds();
	void YoYo();
	void Gravitron(void);
	void ObservationTower();
	void Scrambler();
	void FerrisWheel();
	CSgPtr<CSgComposite> Fence();
	void Fences();

	virtual void Render(DWORD);

	// get the loaded texture ID for this texture name
	// return 0 for invalid texture
	CTexture* GetTexture(const std::string & textureName);

	// cache a texture
	void LoadTexture(const std::string & textureName, const std::string & fileName);

	void StartAnimation(void);
	void StopAnimation(void);

	CSgPtr<CSgComposite> Sidewalk(void);
	void Sidewalks(void);

private:

	// map our 'text' key to a uint (well, texture class) for use with OpenGL
	std::map< std::string, CTexture* > m_textureBinder;

	CSgPtr<CSgComposite> m_root;

	CTexture m_ground;
	CTexture m_sky1;
	CTexture m_sky2;

	CTexture *m_sidewalk;

	FerrisWheelFactory m_fw;
	YoYoFactory m_yoyof;
	ScramblerFactory m_scrambler;
	GravitronFactory m_Gravitron;
	ObservationTowerFactory m_obs;

	bool m_animate;
	
	DWORD m_lastTime; // last animation time
};
